<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        body{
            height: 2500px;
        }
        .head{
            position: fixed;
            top: 0;
            left: 0;
        }
        div{
            width: 100px;
            height: 100px;
            border: 1px solid #666;
            background-color: red;
        }
        #html{
            margin-top: 500px;
        }
        #css{
            margin-top: 500px;
        }
        #js{
            margin-top: 500px;
        }
    </style>
</head>
<body>
    <p class="head">
        <a href="#html">html</a>
        <a href="#css">css</a>
        <a href="#js">js</a>
    </p>
    <div id="html">
        html
    </div>
    <div id="css">
        css
    </div>
    <div id="js">
        javascript
    </div>
    <script>
        $(".head a").click(function(){
            var id = $(this).attr("href")
            var offsetTop = $(id).offset().top;
            $("html,body").animate({
                scrollTop:offsetTop
            })
            return false; 
        })
    </script>
</body>
</html>